package com.example.serivce.impl;

import cn.hutool.core.util.ObjectUtil;
import com.alibaba.excel.EasyExcel;
import com.alibaba.fastjson.JSON;
import com.example.entity.*;
import com.example.mapper.EtlDimSalesDealerInfoHisMapper;
import com.example.moduleName.*;
import com.example.moduleName.nbm.DisplayBoardReq;
import com.example.moduleName.nbm.DisplayBoardRes;
import com.example.moduleName.nbm.NewCarBusinessReq;
import com.example.moduleName.nbm.NewCarBusinessRes;
import com.example.serivce.ExcelReaderService;
import com.example.util.HttpUtils;
import com.example.vo.ModuleNameExportVO;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.net.URLEncoder;
import java.util.*;
import java.util.stream.Collectors;

/**
 * <p>
 * 类名信息
 * </p>
 *
 * @Author haojieshi
 * @Date 2024/4/24 14:08
 * @Version 1.0
 */
@Service
@Slf4j
public class ExcelReaderServiceImpl implements ExcelReaderService {

        @Autowired
        HttpUtils util;
    @Autowired
    EtlDimSalesDealerInfoHisMapper etlDimSalesDealerInfoHisMapper;


    @Override
    public ListVO getEtlDimSalesDealerInfoHis() {
        List<EtlDimSalesDealerInfoHis> etlDimSalesDealerInfoHisList = etlDimSalesDealerInfoHisMapper.selectEtlDimSalesDealerInfoHis();


        List<String> dealerCodes=new ArrayList<>();
        List<Integer> salesAreaCodes=new ArrayList<>();
        List<String> salesAreaNames=new ArrayList<>();
        List<Integer> salesDistCodes=new ArrayList<>();
        List<String> salesDistNames=new ArrayList<>();
        for (EtlDimSalesDealerInfoHis etlDimSalesDealerInfoHis : etlDimSalesDealerInfoHisList) {
            dealerCodes.add(etlDimSalesDealerInfoHis.getDealerCode());
            salesAreaCodes.add(etlDimSalesDealerInfoHis.getSalesAreaCode());
            salesAreaNames.add(etlDimSalesDealerInfoHis.getSalesAreaNameCn());
            salesDistCodes.add(etlDimSalesDealerInfoHis.getSalesDistCode());
            salesDistNames.add(etlDimSalesDealerInfoHis.getSalesDistNameCn());
        }

        dealerCodes = dealerCodes.stream().distinct().collect(Collectors.toList());
        dealerCodes.removeIf(Objects::isNull);

        salesAreaCodes = salesAreaCodes.stream().distinct().collect(Collectors.toList());
        salesAreaCodes.removeIf(Objects::isNull);

        salesAreaNames = salesAreaNames.stream().distinct().collect(Collectors.toList());
        salesAreaNames.removeIf(Objects::isNull);

        salesDistCodes = salesDistCodes.stream().distinct().collect(Collectors.toList());
        salesDistCodes.removeIf(Objects::isNull);

        salesDistNames = salesDistNames.stream().distinct().collect(Collectors.toList());
        salesDistNames.removeIf(Objects::isNull);

        ListVO listVO = new ListVO();

        listVO.setDealerCodes(dealerCodes);
        listVO.setSalesAreaCodes(salesAreaCodes);
        listVO.setSalesDistCodes(salesDistCodes);
        listVO.setSalesAreaNames(salesAreaNames);
        listVO.setSalesDistNames(salesDistNames);

        return listVO;
    }


    //开票目标达成,订单达成,线索目标达成，首次到店达成
    public List<ModuleNameExportVO> getModuleName1() {

        List<ModuleNameExportVO> moduleNameExportVOS=new ArrayList<>();
        SalasOverviewStoreSummaryReq salasOverviewStoreSummaryReq = new SalasOverviewStoreSummaryReq();
        salasOverviewStoreSummaryReq.setBiType("ALL");
        salasOverviewStoreSummaryReq.setCompareType("overview");
        salasOverviewStoreSummaryReq.setDateTypeOptions("M");
        salasOverviewStoreSummaryReq.setYear("2024");
        salasOverviewStoreSummaryReq.setMonth("3");
        salasOverviewStoreSummaryReq.setRoleCode("10461001");
        salasOverviewStoreSummaryReq.setRoleValue("10461001");

        //获取经销商信息
        ListVO listVO = getEtlDimSalesDealerInfoHis();
        List<String> dealerCodes = listVO.getDealerCodes();
        //获取经销商目标值实际值
        for (String dealerCode : dealerCodes) {

            List<String> nationDealerCodes=new ArrayList<>();
            nationDealerCodes.add(dealerCode);
            salasOverviewStoreSummaryReq.setNationDealerCodes(nationDealerCodes);
            String salasOverviewStoreSummary = util.postForReportbi1(salasOverviewStoreSummaryReq);
            SalasOverviewStoreSummaryRes salasOverviewStoreSummaryRes = JSON.parseObject(salasOverviewStoreSummary, SalasOverviewStoreSummaryRes.class);
            SalasOverviewStoreSummaryData data = salasOverviewStoreSummaryRes.getData();
            List<FunnelsFrontEndVo> funnelsFrontEndVo = data.getFunnelsFrontEndVo();
            for (FunnelsFrontEndVo frontEndVo : funnelsFrontEndVo) {
                //开票目标达成
                if (ObjectUtil.equals(frontEndVo.getModelName(),"贡献开票")){
                    ModuleNameExportVO moduleNameExportVO = new ModuleNameExportVO();
                    moduleNameExportVO.setAreaType("310200001");
                    moduleNameExportVO.setModuleName("开票目标达成");
                    moduleNameExportVO.setAreaCode(dealerCode);
                    moduleNameExportVO.setAmt(String.valueOf(frontEndVo.getAmt()));
                    moduleNameExportVO.setTargetAmt(String.valueOf(frontEndVo.getTargetAmt()));
                    moduleNameExportVOS.add(moduleNameExportVO);
                }
                //订单达成
                if (ObjectUtil.equals(frontEndVo.getModelName(),"新增订单")){
                    ModuleNameExportVO moduleNameExportVO1 = new ModuleNameExportVO();
                    moduleNameExportVO1.setAreaType("310200001");
                    moduleNameExportVO1.setModuleName("订单达成");
                    moduleNameExportVO1.setAreaCode(dealerCode);
                    moduleNameExportVO1.setAmt(String.valueOf(frontEndVo.getAmt()));
                    moduleNameExportVO1.setTargetAmt(String.valueOf(frontEndVo.getTargetAmt()));
                    moduleNameExportVOS.add(moduleNameExportVO1);
                }
                //线索目标达成
                if (ObjectUtil.equals(frontEndVo.getModelName(),"线索")){
                    ModuleNameExportVO moduleNameExportVO2 = new ModuleNameExportVO();
                    moduleNameExportVO2.setAreaType("310200001");
                    moduleNameExportVO2.setModuleName("线索目标达成");
                    moduleNameExportVO2.setAreaCode(dealerCode);
                    moduleNameExportVO2.setAmt(String.valueOf(frontEndVo.getAmt()));
                    moduleNameExportVO2.setTargetAmt(String.valueOf(frontEndVo.getTargetAmt()));
                    moduleNameExportVOS.add(moduleNameExportVO2);
                }
                //首次到店达成
                if (ObjectUtil.equals(frontEndVo.getModelName(),"首次到店")){
                    ModuleNameExportVO moduleNameExportVO3 = new ModuleNameExportVO();
                    moduleNameExportVO3.setAreaType("310200001");
                    moduleNameExportVO3.setModuleName("首次到店达成");
                    moduleNameExportVO3.setAreaCode(dealerCode);
                    moduleNameExportVO3.setAmt(String.valueOf(frontEndVo.getAmt()));
                    moduleNameExportVO3.setTargetAmt(String.valueOf(frontEndVo.getTargetAmt()));
                    moduleNameExportVOS.add(moduleNameExportVO3);
                }
            }
        }
        salasOverviewStoreSummaryReq.setNationDealerCodes(null);

        //获取销售大区目标值实际值
        List<Integer> salesAreaCodes = listVO.getSalesAreaCodes();
        for (Integer salesAreaCode : salesAreaCodes) {

            List<Integer> nationAreaCodes=new ArrayList<>();
            nationAreaCodes.add(salesAreaCode);
            salasOverviewStoreSummaryReq.setNationAreaCodes(nationAreaCodes);
            String salasOverviewStoreSummary = util.postForReportbi1(salasOverviewStoreSummaryReq);
            SalasOverviewStoreSummaryRes salasOverviewStoreSummaryRes = JSON.parseObject(salasOverviewStoreSummary, SalasOverviewStoreSummaryRes.class);
            SalasOverviewStoreSummaryData data = salasOverviewStoreSummaryRes.getData();
            List<FunnelsFrontEndVo> funnelsFrontEndVo = data.getFunnelsFrontEndVo();
            for (FunnelsFrontEndVo frontEndVo : funnelsFrontEndVo) {
                //开票目标达成
                if (ObjectUtil.equals(frontEndVo.getModelName(),"贡献开票")){
                    ModuleNameExportVO moduleNameExportVO = new ModuleNameExportVO();
                    moduleNameExportVO.setAreaType("310200004");
                    moduleNameExportVO.setModuleName("开票目标达成");
                    moduleNameExportVO.setAreaCode(String.valueOf(salesAreaCode));
                    moduleNameExportVO.setAmt(String.valueOf(frontEndVo.getAmt()));
                    moduleNameExportVO.setTargetAmt(String.valueOf(frontEndVo.getTargetAmt()));
                    moduleNameExportVOS.add(moduleNameExportVO);
                }
                //订单达成
                if (ObjectUtil.equals(frontEndVo.getModelName(),"新增订单")){
                    ModuleNameExportVO moduleNameExportVO1 = new ModuleNameExportVO();
                    moduleNameExportVO1.setAreaType("310200004");
                    moduleNameExportVO1.setModuleName("订单达成");
                    moduleNameExportVO1.setAreaCode(String.valueOf(salesAreaCode));
                    moduleNameExportVO1.setAmt(String.valueOf(frontEndVo.getAmt()));
                    moduleNameExportVO1.setTargetAmt(String.valueOf(frontEndVo.getTargetAmt()));
                    moduleNameExportVOS.add(moduleNameExportVO1);
                }
                //线索目标达成
                if (ObjectUtil.equals(frontEndVo.getModelName(),"线索")){
                    ModuleNameExportVO moduleNameExportVO2 = new ModuleNameExportVO();
                    moduleNameExportVO2.setAreaType("310200004");
                    moduleNameExportVO2.setModuleName("线索目标达成");
                    moduleNameExportVO2.setAreaCode(String.valueOf(salesAreaCode));
                    moduleNameExportVO2.setAmt(String.valueOf(frontEndVo.getAmt()));
                    moduleNameExportVO2.setTargetAmt(String.valueOf(frontEndVo.getTargetAmt()));
                    moduleNameExportVOS.add(moduleNameExportVO2);
                }
                //首次到店达成
                if (ObjectUtil.equals(frontEndVo.getModelName(),"首次到店")){
                    ModuleNameExportVO moduleNameExportVO3 = new ModuleNameExportVO();
                    moduleNameExportVO3.setAreaType("310200004");
                    moduleNameExportVO3.setModuleName("首次到店达成");
                    moduleNameExportVO3.setAreaCode(String.valueOf(salesAreaCode));
                    moduleNameExportVO3.setAmt(String.valueOf(frontEndVo.getAmt()));
                    moduleNameExportVO3.setTargetAmt(String.valueOf(frontEndVo.getTargetAmt()));
                    moduleNameExportVOS.add(moduleNameExportVO3);
                }
            }
        }
        salasOverviewStoreSummaryReq.setNationAreaCodes(null);

        //获取销售小区目标值实际值
        List<Integer> salesDistCodes = listVO.getSalesDistCodes();
        for (Integer salesDistCode : salesDistCodes) {
            List<Integer> nationSmallDistIds=new ArrayList<>();
            nationSmallDistIds.add(salesDistCode);
            salasOverviewStoreSummaryReq.setNationSmallDistIds(nationSmallDistIds);
            String salasOverviewStoreSummary = util.postForReportbi1(salasOverviewStoreSummaryReq);
            SalasOverviewStoreSummaryRes salasOverviewStoreSummaryRes = JSON.parseObject(salasOverviewStoreSummary, SalasOverviewStoreSummaryRes.class);
            SalasOverviewStoreSummaryData data = salasOverviewStoreSummaryRes.getData();
            List<FunnelsFrontEndVo> funnelsFrontEndVo = data.getFunnelsFrontEndVo();
            for (FunnelsFrontEndVo frontEndVo : funnelsFrontEndVo) {
                //开票目标达成
                if (ObjectUtil.equals(frontEndVo.getModelName(),"贡献开票")){
                    ModuleNameExportVO moduleNameExportVO = new ModuleNameExportVO();
                    moduleNameExportVO.setAreaType("310200002");
                    moduleNameExportVO.setModuleName("开票目标达成");
                    moduleNameExportVO.setAreaCode(String.valueOf(salesDistCode));
                    moduleNameExportVO.setAmt(String.valueOf(frontEndVo.getAmt()));
                    moduleNameExportVO.setTargetAmt(String.valueOf(frontEndVo.getTargetAmt()));
                    moduleNameExportVOS.add(moduleNameExportVO);
                }
                //订单达成
                if (ObjectUtil.equals(frontEndVo.getModelName(),"新增订单")){
                    ModuleNameExportVO moduleNameExportVO1 = new ModuleNameExportVO();
                    moduleNameExportVO1.setAreaType("310200002");
                    moduleNameExportVO1.setModuleName("订单达成");
                    moduleNameExportVO1.setAreaCode(String.valueOf(salesDistCode));
                    moduleNameExportVO1.setAmt(String.valueOf(frontEndVo.getAmt()));
                    moduleNameExportVO1.setTargetAmt(String.valueOf(frontEndVo.getTargetAmt()));
                    moduleNameExportVOS.add(moduleNameExportVO1);
                }
                //线索目标达成
                if (ObjectUtil.equals(frontEndVo.getModelName(),"线索")){
                    ModuleNameExportVO moduleNameExportVO2 = new ModuleNameExportVO();
                    moduleNameExportVO2.setAreaType("310200002");
                    moduleNameExportVO2.setModuleName("线索目标达成");
                    moduleNameExportVO2.setAreaCode(String.valueOf(salesDistCode));
                    moduleNameExportVO2.setAmt(String.valueOf(frontEndVo.getAmt()));
                    moduleNameExportVO2.setTargetAmt(String.valueOf(frontEndVo.getTargetAmt()));
                    moduleNameExportVOS.add(moduleNameExportVO2);
                }
                //首次到店达成
                if (ObjectUtil.equals(frontEndVo.getModelName(),"首次到店")){
                    ModuleNameExportVO moduleNameExportVO3 = new ModuleNameExportVO();
                    moduleNameExportVO3.setAreaType("310200002");
                    moduleNameExportVO3.setModuleName("首次到店达成");
                    moduleNameExportVO3.setAreaCode(String.valueOf(salesDistCode));
                    moduleNameExportVO3.setAmt(String.valueOf(frontEndVo.getAmt()));
                    moduleNameExportVO3.setTargetAmt(String.valueOf(frontEndVo.getTargetAmt()));
                    moduleNameExportVOS.add(moduleNameExportVO3);
                }
            }
        }
        salasOverviewStoreSummaryReq.setNationSmallDistIds(null);

        //获取全国实际值目标值
        String salasOverviewStoreSummary = util.postForReportbi1(salasOverviewStoreSummaryReq);
        SalasOverviewStoreSummaryRes salasOverviewStoreSummaryRes = JSON.parseObject(salasOverviewStoreSummary, SalasOverviewStoreSummaryRes.class);
        SalasOverviewStoreSummaryData data = salasOverviewStoreSummaryRes.getData();
        List<FunnelsFrontEndVo> funnelsFrontEndVo = data.getFunnelsFrontEndVo();
        for (FunnelsFrontEndVo frontEndVo : funnelsFrontEndVo) {
            if (ObjectUtil.equals(frontEndVo.getModelName(),"贡献开票")){
                ModuleNameExportVO moduleNameExportVO = new ModuleNameExportVO();
                moduleNameExportVO.setAreaType("310200099");
                moduleNameExportVO.setModuleName("开票目标达成");
                moduleNameExportVO.setAreaCode("0");
                moduleNameExportVO.setAmt(String.valueOf(frontEndVo.getAmt()));
                moduleNameExportVO.setTargetAmt(String.valueOf(frontEndVo.getTargetAmt()));
                moduleNameExportVOS.add(moduleNameExportVO);
            }
            //订单达成
            if (ObjectUtil.equals(frontEndVo.getModelName(),"新增订单")){
                ModuleNameExportVO moduleNameExportVO1 = new ModuleNameExportVO();
                moduleNameExportVO1.setAreaType("310200099");
                moduleNameExportVO1.setModuleName("订单达成");
                moduleNameExportVO1.setAreaCode("0");
                moduleNameExportVO1.setAmt(String.valueOf(frontEndVo.getAmt()));
                moduleNameExportVO1.setTargetAmt(String.valueOf(frontEndVo.getTargetAmt()));
                moduleNameExportVOS.add(moduleNameExportVO1);
            }
            //线索目标达成
            if (ObjectUtil.equals(frontEndVo.getModelName(),"线索")){
                ModuleNameExportVO moduleNameExportVO2 = new ModuleNameExportVO();
                moduleNameExportVO2.setAreaType("310200099");
                moduleNameExportVO2.setModuleName("线索目标达成");
                moduleNameExportVO2.setAreaCode("0");
                moduleNameExportVO2.setAmt(String.valueOf(frontEndVo.getAmt()));
                moduleNameExportVO2.setTargetAmt(String.valueOf(frontEndVo.getTargetAmt()));
                moduleNameExportVOS.add(moduleNameExportVO2);
            }
            //首次到店达成
            if (ObjectUtil.equals(frontEndVo.getModelName(),"首次到店")){
                ModuleNameExportVO moduleNameExportVO3 = new ModuleNameExportVO();
                moduleNameExportVO3.setAreaType("310200099");
                moduleNameExportVO3.setModuleName("首次到店达成");
                moduleNameExportVO3.setAreaCode("0");
                moduleNameExportVO3.setAmt(String.valueOf(frontEndVo.getAmt()));
                moduleNameExportVO3.setTargetAmt(String.valueOf(frontEndVo.getTargetAmt()));
                moduleNameExportVOS.add(moduleNameExportVO3);
            }
        }

        return moduleNameExportVOS;
    }


    //看车客户批次比,看车客户进店时间间隔,非客占比，划拨率
    public List<ModuleNameExportVO> getModuleName2() {

        List<ModuleNameExportVO> moduleNameExportVOS=new ArrayList<>();
        //看车客户批次比,看车客户进店时间间隔,非客占比，划拨率
        SalasManageStatDataReq salasManageStatDataReq=new SalasManageStatDataReq();
        salasManageStatDataReq.setMescroll(true);
        salasManageStatDataReq.setTabType("ALL");
        salasManageStatDataReq.setMonth("3");
        salasManageStatDataReq.setRoleValue("10461001");
        salasManageStatDataReq.setYear("2024");
        salasManageStatDataReq.setSql_tab("AI客流");
        salasManageStatDataReq.setBiType("4S");
        salasManageStatDataReq.setSql_category("管理指标_概览_AI客流_渲染区域");
        salasManageStatDataReq.setRoleCode("10461001");
        salasManageStatDataReq.setDateTypeOptions("M");
        salasManageStatDataReq.setCompareType("overview");
        //24H外呼率
        SalasManageStatDataReq salasManageStatDataReq1=new SalasManageStatDataReq();
        salasManageStatDataReq1.setYear("2024");
        salasManageStatDataReq1.setTabType("AI_SC");
        salasManageStatDataReq1.setBiType("4S");
        salasManageStatDataReq1.setDateTypeOptions("M");
        salasManageStatDataReq1.setCompareType("overview");
        salasManageStatDataReq1.setRoleCode("10461001");
        salasManageStatDataReq1.setRoleValue("10461001");
        salasManageStatDataReq1.setSql_category("管理指标_概览_AI外呼进度_渲染区域");
        salasManageStatDataReq1.setMonth("3");
        salasManageStatDataReq1.setSql_tab("AI外呼");
        salasManageStatDataReq1.setMescroll(true);

        //获取全国实际值目标值
        String salasManageStatData1 = util.postForReportbi2(salasManageStatDataReq);
        SalasManageStatDataRes salasManageStatDataRes1 = JSON.parseObject(salasManageStatData1, SalasManageStatDataRes.class);
        SalasManageStatData data1 = salasManageStatDataRes1.getData();
        List<JSONDatum> jsonData1 = data1.getJsonData();
        String targetAmtC1 =null;
        String targetAmtC2 =null;
        String targetAmtC5 =null;
        for (JSONDatum jsonDatum : jsonData1) {
            //看车客户批次比
            ModuleNameExportVO moduleNameExportVO = new ModuleNameExportVO();
            moduleNameExportVO.setAreaType("310200099");
            moduleNameExportVO.setModuleName("看车客户批次比");
            moduleNameExportVO.setAreaCode("0");
            moduleNameExportVO.setAmt(String.valueOf(jsonDatum.getC1()));
            moduleNameExportVO.setTargetAmt(String.valueOf(jsonDatum.getC1()));
            targetAmtC1 =String.valueOf(jsonDatum.getC1());
            moduleNameExportVOS.add(moduleNameExportVO);
            //看车客户进店时间间隔
            ModuleNameExportVO moduleNameExportVO1 = new ModuleNameExportVO();
            moduleNameExportVO1.setAreaType("310200099");
            moduleNameExportVO1.setModuleName("看车客户进店时间间隔");
            moduleNameExportVO1.setAreaCode("0");
            moduleNameExportVO1.setAmt(String.valueOf(jsonDatum.getC2()));
            moduleNameExportVO1.setTargetAmt(String.valueOf(jsonDatum.getC2()));
            targetAmtC2 =String.valueOf(jsonDatum.getC2());
            moduleNameExportVOS.add(moduleNameExportVO1);
            //划拨率
            ModuleNameExportVO moduleNameExportVO2 = new ModuleNameExportVO();
            moduleNameExportVO2.setAreaType("310200099");
            moduleNameExportVO2.setModuleName("划拨率");
            moduleNameExportVO2.setAreaCode("0");
            moduleNameExportVO2.setAmt(String.valueOf(jsonDatum.getC3()));
            moduleNameExportVOS.add(moduleNameExportVO2);
            //非客占比
            ModuleNameExportVO moduleNameExportVO3 = new ModuleNameExportVO();
            moduleNameExportVO3.setAreaType("310200099");
            moduleNameExportVO3.setModuleName("非客占比");
            moduleNameExportVO3.setAreaCode("0");
            moduleNameExportVO3.setAmt(String.valueOf(jsonDatum.getC5()));
            moduleNameExportVO3.setTargetAmt(String.valueOf(jsonDatum.getC5()));
            targetAmtC5 =String.valueOf(jsonDatum.getC5());
            moduleNameExportVOS.add(moduleNameExportVO3);
        }

        //24H外呼率
        {
            String salasManageStatData2 = util.postForReportbi2(salasManageStatDataReq1);
            SalasManageStatDataRes salasManageStatDataRes2 = JSON.parseObject(salasManageStatData2, SalasManageStatDataRes.class);
            SalasManageStatData data2 = salasManageStatDataRes2.getData();
            List<JSONDatum> jsonData2 = data2.getJsonData();
            for (JSONDatum jsonDatum : jsonData2) {
                //24H外呼率
                ModuleNameExportVO moduleNameExportVO = new ModuleNameExportVO();
                moduleNameExportVO.setAreaType("310200099");
                moduleNameExportVO.setModuleName("24H外呼率");
                moduleNameExportVO.setAreaCode("0");
                moduleNameExportVO.setAmt(String.valueOf(jsonDatum.getC13()));
                moduleNameExportVOS.add(moduleNameExportVO);
            }
        }



        //获取经销商信息
        ListVO listVO = getEtlDimSalesDealerInfoHis();
        List<String> dealerCodes = listVO.getDealerCodes();
        //获取经销商目标值实际值
        for (String dealerCode : dealerCodes) {

            List<String> nationDealerCodes=new ArrayList<>();
            nationDealerCodes.add(dealerCode);
            salasManageStatDataReq.setNationDealerCodes(nationDealerCodes);
            String salasManageStatData = util.postForReportbi2(salasManageStatDataReq);
            SalasManageStatDataRes salasManageStatDataRes = JSON.parseObject(salasManageStatData, SalasManageStatDataRes.class);
            SalasManageStatData data = salasManageStatDataRes.getData();
            List<JSONDatum> jsonData = data.getJsonData();
            for (JSONDatum jsonDatum : jsonData) {
                ModuleNameExportVO moduleNameExportVO = new ModuleNameExportVO();
                //看车客户批次比
                moduleNameExportVO.setAreaType("310200001");
                moduleNameExportVO.setModuleName("看车客户批次比");
                moduleNameExportVO.setAreaCode(dealerCode);
                moduleNameExportVO.setAmt(String.valueOf(jsonDatum.getC1()));
                moduleNameExportVO.setTargetAmt(targetAmtC1);
                moduleNameExportVOS.add(moduleNameExportVO);
                //看车客户进店时间间隔
                ModuleNameExportVO moduleNameExportVO1 = new ModuleNameExportVO();
                moduleNameExportVO1.setAreaType("310200001");
                moduleNameExportVO1.setModuleName("看车客户进店时间间隔");
                moduleNameExportVO1.setAreaCode(dealerCode);
                moduleNameExportVO1.setAmt(String.valueOf(jsonDatum.getC2()));
                moduleNameExportVO1.setTargetAmt(targetAmtC2);
                moduleNameExportVOS.add(moduleNameExportVO1);
                //划拨率
                ModuleNameExportVO moduleNameExportVO2 = new ModuleNameExportVO();
                moduleNameExportVO2.setAreaType("310200001");
                moduleNameExportVO2.setModuleName("划拨率");
                moduleNameExportVO2.setAreaCode(dealerCode);
                moduleNameExportVO2.setAmt(String.valueOf(jsonDatum.getC3()));
                moduleNameExportVOS.add(moduleNameExportVO2);
                //非客占比
                ModuleNameExportVO moduleNameExportVO3 = new ModuleNameExportVO();
                moduleNameExportVO3.setAreaType("310200001");
                moduleNameExportVO3.setModuleName("非客占比");
                moduleNameExportVO3.setAreaCode(dealerCode);
                moduleNameExportVO3.setAmt(String.valueOf(jsonDatum.getC5()));
                moduleNameExportVO3.setTargetAmt(targetAmtC5);
                moduleNameExportVOS.add(moduleNameExportVO3);
            }
            //24H外呼率
            salasManageStatDataReq1.setNationDealerCodes(nationDealerCodes);
            String salasManageStatData2 = util.postForReportbi2(salasManageStatDataReq1);
            SalasManageStatDataRes salasManageStatDataRes2 = JSON.parseObject(salasManageStatData2, SalasManageStatDataRes.class);
            SalasManageStatData data2 = salasManageStatDataRes2.getData();
            List<JSONDatum> jsonData2 = data2.getJsonData();
            for (JSONDatum jsonDatum : jsonData2) {
                //24H外呼率
                ModuleNameExportVO moduleNameExportVO = new ModuleNameExportVO();
                moduleNameExportVO.setAreaType("310200001");
                moduleNameExportVO.setModuleName("24H外呼率");
                moduleNameExportVO.setAreaCode(dealerCode);
                moduleNameExportVO.setAmt(String.valueOf(jsonDatum.getC13()));
                moduleNameExportVOS.add(moduleNameExportVO);
            }
        }
        salasManageStatDataReq.setNationDealerCodes(null);
        salasManageStatDataReq1.setNationDealerCodes(null);

        //获取销售大区目标值实际值
        List<Integer> salesAreaCodes = listVO.getSalesAreaCodes();
        for (Integer salesAreaCode : salesAreaCodes) {

            List<Integer> nationAreaCodes=new ArrayList<>();
            nationAreaCodes.add(salesAreaCode);
            salasManageStatDataReq.setNationAreaCodes(nationAreaCodes);
            String salasManageStatData = util.postForReportbi2(salasManageStatDataReq);
            SalasManageStatDataRes salasManageStatDataRes = JSON.parseObject(salasManageStatData, SalasManageStatDataRes.class);
            SalasManageStatData data = salasManageStatDataRes.getData();
            List<JSONDatum> jsonData = data.getJsonData();
            for (JSONDatum jsonDatum : jsonData) {
                ModuleNameExportVO moduleNameExportVO = new ModuleNameExportVO();
                //看车客户批次比
                moduleNameExportVO.setAreaType("310200004");
                moduleNameExportVO.setModuleName("看车客户批次比");
                moduleNameExportVO.setAreaCode(String.valueOf(salesAreaCode));
                moduleNameExportVO.setAmt(String.valueOf(jsonDatum.getC1()));
                moduleNameExportVO.setTargetAmt(targetAmtC1);
                moduleNameExportVOS.add(moduleNameExportVO);
                //看车客户进店时间间隔
                ModuleNameExportVO moduleNameExportVO1 = new ModuleNameExportVO();
                moduleNameExportVO1.setAreaType("310200004");
                moduleNameExportVO1.setModuleName("看车客户进店时间间隔");
                moduleNameExportVO1.setAreaCode(String.valueOf(salesAreaCode));
                moduleNameExportVO1.setAmt(String.valueOf(jsonDatum.getC2()));
                moduleNameExportVO1.setTargetAmt(targetAmtC2);
                moduleNameExportVOS.add(moduleNameExportVO1);
                //划拨率
                ModuleNameExportVO moduleNameExportVO2 = new ModuleNameExportVO();
                moduleNameExportVO2.setAreaType("310200004");
                moduleNameExportVO2.setModuleName("划拨率");
                moduleNameExportVO2.setAreaCode(String.valueOf(salesAreaCode));
                moduleNameExportVO2.setAmt(String.valueOf(jsonDatum.getC3()));
                moduleNameExportVOS.add(moduleNameExportVO2);
                //非客占比
                ModuleNameExportVO moduleNameExportVO3 = new ModuleNameExportVO();
                moduleNameExportVO3.setAreaType("310200004");
                moduleNameExportVO3.setModuleName("非客占比");
                moduleNameExportVO3.setAreaCode(String.valueOf(salesAreaCode));
                moduleNameExportVO3.setAmt(String.valueOf(jsonDatum.getC5()));
                moduleNameExportVO3.setTargetAmt(targetAmtC5);
                moduleNameExportVOS.add(moduleNameExportVO3);
            }
            //24H外呼率
            salasManageStatDataReq1.setNationAreaCodes(nationAreaCodes);
            String salasManageStatData2 = util.postForReportbi2(salasManageStatDataReq1);
            SalasManageStatDataRes salasManageStatDataRes2 = JSON.parseObject(salasManageStatData2, SalasManageStatDataRes.class);
            SalasManageStatData data2 = salasManageStatDataRes2.getData();
            List<JSONDatum> jsonData2 = data2.getJsonData();
            for (JSONDatum jsonDatum : jsonData2) {
                //24H外呼率
                ModuleNameExportVO moduleNameExportVO = new ModuleNameExportVO();
                moduleNameExportVO.setAreaType("310200004");
                moduleNameExportVO.setModuleName("24H外呼率");
                moduleNameExportVO.setAreaCode(String.valueOf(salesAreaCode));
                moduleNameExportVO.setAmt(String.valueOf(jsonDatum.getC13()));
                moduleNameExportVOS.add(moduleNameExportVO);
            }

        }
        salasManageStatDataReq.setNationAreaCodes(null);
        salasManageStatDataReq1.setNationAreaCodes(null);

        //获取销售小区目标值实际值
        List<Integer> salesDistCodes = listVO.getSalesDistCodes();
        for (Integer salesDistCode : salesDistCodes) {

            List<Integer> nationSmallDistIds=new ArrayList<>();
            nationSmallDistIds.add(salesDistCode);
            salasManageStatDataReq.setNationSmallDistIds(nationSmallDistIds);
            String salasManageStatData = util.postForReportbi2(salasManageStatDataReq);
            SalasManageStatDataRes salasManageStatDataRes = JSON.parseObject(salasManageStatData, SalasManageStatDataRes.class);
            SalasManageStatData data = salasManageStatDataRes.getData();
            List<JSONDatum> jsonData = data.getJsonData();
            for (JSONDatum jsonDatum : jsonData) {
                ModuleNameExportVO moduleNameExportVO = new ModuleNameExportVO();
                moduleNameExportVO.setAreaType("310200002");
                moduleNameExportVO.setModuleName("看车客户批次比");
                moduleNameExportVO.setAreaCode(String.valueOf(salesDistCode));
                moduleNameExportVO.setAmt(String.valueOf(jsonDatum.getC1()));
                moduleNameExportVO.setTargetAmt(targetAmtC1);
                moduleNameExportVOS.add(moduleNameExportVO);
                //看车客户进店时间间隔
                ModuleNameExportVO moduleNameExportVO1 = new ModuleNameExportVO();
                moduleNameExportVO1.setAreaType("310200002");
                moduleNameExportVO1.setModuleName("看车客户进店时间间隔");
                moduleNameExportVO1.setAreaCode(String.valueOf(salesDistCode));
                moduleNameExportVO1.setAmt(String.valueOf(jsonDatum.getC2()));
                moduleNameExportVO1.setTargetAmt(targetAmtC2);
                moduleNameExportVOS.add(moduleNameExportVO1);
                //划拨率
                ModuleNameExportVO moduleNameExportVO2 = new ModuleNameExportVO();
                moduleNameExportVO2.setAreaType("310200002");
                moduleNameExportVO2.setModuleName("划拨率");
                moduleNameExportVO2.setAreaCode(String.valueOf(salesDistCode));
                moduleNameExportVO2.setAmt(String.valueOf(jsonDatum.getC3()));
                moduleNameExportVOS.add(moduleNameExportVO2);
                //非客占比
                ModuleNameExportVO moduleNameExportVO3 = new ModuleNameExportVO();
                moduleNameExportVO3.setAreaType("310200002");
                moduleNameExportVO3.setModuleName("非客占比");
                moduleNameExportVO3.setAreaCode(String.valueOf(salesDistCode));
                moduleNameExportVO3.setAmt(String.valueOf(jsonDatum.getC5()));
                moduleNameExportVO3.setTargetAmt(targetAmtC5);
                moduleNameExportVOS.add(moduleNameExportVO3);
            }
            //24H外呼率
            salasManageStatDataReq1.setNationSmallDistIds(nationSmallDistIds);
            String salasManageStatData2 = util.postForReportbi2(salasManageStatDataReq1);
            SalasManageStatDataRes salasManageStatDataRes2 = JSON.parseObject(salasManageStatData2, SalasManageStatDataRes.class);
            SalasManageStatData data2 = salasManageStatDataRes2.getData();
            List<JSONDatum> jsonData2 = data2.getJsonData();
            for (JSONDatum jsonDatum : jsonData2) {
                //24H外呼率
                ModuleNameExportVO moduleNameExportVO = new ModuleNameExportVO();
                moduleNameExportVO.setAreaType("310200002");
                moduleNameExportVO.setModuleName("24H外呼率");
                moduleNameExportVO.setAreaCode(String.valueOf(salesDistCode));
                moduleNameExportVO.setAmt(String.valueOf(jsonDatum.getC13()));
                moduleNameExportVOS.add(moduleNameExportVO);
            }
        }

        return moduleNameExportVOS;
    }


    //DCC全渠道首邀率,DCC订单占比,成交率
    public List<ModuleNameExportVO> getModuleName3() {

        List<ModuleNameExportVO> moduleNameExportVOS=new ArrayList<>();
        SalasOverviewReq salasOverviewReq=new SalasOverviewReq();
        salasOverviewReq.setYear("2024");
        salasOverviewReq.setBiType("All");
        salasOverviewReq.setDateTypeOptions("M");
        salasOverviewReq.setCompareType("overview");
        salasOverviewReq.setRoleCode("10461001");
        salasOverviewReq.setRoleValue("10461001");
        salasOverviewReq.setMonth("3");

        //去除展厅到店
        SalasOverviewReq salasOverviewReq1=new SalasOverviewReq();
        salasOverviewReq1.setYear("2024");
        salasOverviewReq1.setBiType("All");
        salasOverviewReq1.setDateTypeOptions("M");
        salasOverviewReq1.setCompareType("overview");
        salasOverviewReq1.setRoleCode("10461001");
        salasOverviewReq1.setRoleValue("10461001");
        salasOverviewReq1.setMonth("3");
        List<String> lvl1ChannelIds =new ArrayList<>();
        lvl1ChannelIds.add("300500001");
        lvl1ChannelIds.add("300500002");
        lvl1ChannelIds.add("300500006");
        lvl1ChannelIds.add("300500004");
        lvl1ChannelIds.add("300500005");
        lvl1ChannelIds.add("300500003");
        lvl1ChannelIds.add("300500008");
        salasOverviewReq1.setLvl1ChannelIds(lvl1ChannelIds);



        //获取经销商信息
        ListVO listVO = getEtlDimSalesDealerInfoHis();
        List<String> dealerCodes = listVO.getDealerCodes();
        //获取经销商目标值实际值
        for (String dealerCode : dealerCodes) {
            List<String> nationDealerCodes=new ArrayList<>();
            nationDealerCodes.add(dealerCode);
            salasOverviewReq.setNationDealerCodes(nationDealerCodes);
            salasOverviewReq1.setNationDealerCodes(nationDealerCodes);
            String salasOverview1 = util.postForReportbi3(salasOverviewReq);
            SalasOverviewRes salasOverviewRes1 = JSON.parseObject(salasOverview1, SalasOverviewRes.class);
            SalasOverviewData data1 = salasOverviewRes1.getData();
            List<SalasOverviewResFunnelsFrontEndVo> funnelsFrontEndVo1 = data1.getFunnelsFrontEndVo();
            //DCC全渠道首邀率实际值
            BigDecimal amt = null;
            //DCC订单占比
            BigDecimal amt1 = null;
            //成交率
            BigDecimal amt2 = null;

                for (SalasOverviewResFunnelsFrontEndVo salasOverviewResFunnelsFrontEndVo : funnelsFrontEndVo1) {
                    if (ObjectUtil.equals(salasOverviewResFunnelsFrontEndVo.getModelName(),"新增订单")){
                        amt1  = new BigDecimal(salasOverviewResFunnelsFrontEndVo.getAmt());
                        amt2  = new BigDecimal(salasOverviewResFunnelsFrontEndVo.getAmt());
                    }
                }
                for (SalasOverviewResFunnelsFrontEndVo salasOverviewResFunnelsFrontEndVo : funnelsFrontEndVo1) {
                    if (ObjectUtil.equals(salasOverviewResFunnelsFrontEndVo.getModelName(),"首次到店")){
                        BigDecimal bigDecimal1 = new BigDecimal(salasOverviewResFunnelsFrontEndVo.getAmt());
                        BigDecimal bigDecimal2 = new BigDecimal(salasOverviewResFunnelsFrontEndVo.getAmt1());
                        amt = bigDecimal1.subtract(bigDecimal2);
                        try {
                            amt2 =amt2.divide(new BigDecimal(salasOverviewResFunnelsFrontEndVo.getAmt()),8, RoundingMode.HALF_UP);
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    }
                }
                //去除展厅到店
                String salasOverview2 = util.postForReportbi3(salasOverviewReq1);
                SalasOverviewRes salasOverviewRes2 = JSON.parseObject(salasOverview2, SalasOverviewRes.class);
                SalasOverviewData data2 = salasOverviewRes2.getData();
                List<SalasOverviewResFunnelsFrontEndVo> funnelsFrontEndVo2 = data2.getFunnelsFrontEndVo();
                for (SalasOverviewResFunnelsFrontEndVo salasOverviewResFunnelsFrontEndVo : funnelsFrontEndVo2) {
                    if (ObjectUtil.equals(salasOverviewResFunnelsFrontEndVo.getModelName(),"线索")){
                        BigDecimal bigDecimal3 = new BigDecimal(salasOverviewResFunnelsFrontEndVo.getAmt());
                        try {
                            amt = amt.divide(bigDecimal3,8, RoundingMode.HALF_UP);
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    }
                    if (ObjectUtil.equals(salasOverviewResFunnelsFrontEndVo.getModelName(),"新增订单")){
                        try {
                            amt1= amt1.divide(new BigDecimal(salasOverviewResFunnelsFrontEndVo.getAmt()),8, RoundingMode.HALF_UP);
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    }
                }

            //DCC全渠道首邀率
            ModuleNameExportVO moduleNameExportVO = new ModuleNameExportVO();
            moduleNameExportVO.setAreaType("310200001");
            moduleNameExportVO.setModuleName("DCC全渠道首邀率");
            moduleNameExportVO.setAreaCode(dealerCode);
            moduleNameExportVO.setAmt(String.valueOf(amt));
            moduleNameExportVOS.add(moduleNameExportVO);

            //DCC订单占比
            ModuleNameExportVO moduleNameExportVO1 = new ModuleNameExportVO();
            moduleNameExportVO1.setAreaType("310200001");
            moduleNameExportVO1.setModuleName("DCC订单占比");
            moduleNameExportVO1.setAreaCode(dealerCode);
            moduleNameExportVO1.setAmt(String.valueOf(amt1));
            moduleNameExportVOS.add(moduleNameExportVO1);

            //成交率
            ModuleNameExportVO moduleNameExportVO2 = new ModuleNameExportVO();
            moduleNameExportVO2.setAreaType("310200001");
            moduleNameExportVO2.setModuleName("成交率");
            moduleNameExportVO2.setAreaCode(dealerCode);
            moduleNameExportVO2.setAmt(String.valueOf(amt2));
            moduleNameExportVOS.add(moduleNameExportVO2);
        }
        salasOverviewReq.setNationDealerCodes(null);
        salasOverviewReq1.setNationDealerCodes(null);

        //获取销售大区目标值实际值
        List<Integer> salesAreaCodes = listVO.getSalesAreaCodes();
        for (Integer salesAreaCode : salesAreaCodes) {

            List<Integer> nationAreaCodes=new ArrayList<>();
            nationAreaCodes.add(salesAreaCode);
            salasOverviewReq.setNationAreaCodes(nationAreaCodes);
            salasOverviewReq1.setNationAreaCodes(nationAreaCodes);
            String salasOverview1 = util.postForReportbi3(salasOverviewReq);
            SalasOverviewRes salasOverviewRes1 = JSON.parseObject(salasOverview1, SalasOverviewRes.class);
            SalasOverviewData data1 = salasOverviewRes1.getData();
            List<SalasOverviewResFunnelsFrontEndVo> funnelsFrontEndVo1 = data1.getFunnelsFrontEndVo();
            //DCC全渠道首邀率实际值
            BigDecimal amt = null;
            //DCC订单占比
            BigDecimal amt1 = null;
            //成交率
            BigDecimal amt2 = null;
                for (SalasOverviewResFunnelsFrontEndVo salasOverviewResFunnelsFrontEndVo : funnelsFrontEndVo1) {
                    if (ObjectUtil.equals(salasOverviewResFunnelsFrontEndVo.getModelName(),"新增订单")){
                        amt1  = new BigDecimal(salasOverviewResFunnelsFrontEndVo.getAmt());
                        amt2  = new BigDecimal(salasOverviewResFunnelsFrontEndVo.getAmt());
                    }
                }
                for (SalasOverviewResFunnelsFrontEndVo salasOverviewResFunnelsFrontEndVo : funnelsFrontEndVo1) {
                    if (ObjectUtil.equals(salasOverviewResFunnelsFrontEndVo.getModelName(),"首次到店")){
                        BigDecimal bigDecimal1 = new BigDecimal(salasOverviewResFunnelsFrontEndVo.getAmt());
                        BigDecimal bigDecimal2 = new BigDecimal(salasOverviewResFunnelsFrontEndVo.getAmt1());
                        amt = bigDecimal1.subtract(bigDecimal2);
                        try {
                            amt2 =amt2.divide(new BigDecimal(salasOverviewResFunnelsFrontEndVo.getAmt()),8, RoundingMode.HALF_UP);
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    }
                }
                //去除展厅到店
                String salasOverview2 = util.postForReportbi3(salasOverviewReq1);
                SalasOverviewRes salasOverviewRes2 = JSON.parseObject(salasOverview2, SalasOverviewRes.class);
                SalasOverviewData data2 = salasOverviewRes2.getData();
                List<SalasOverviewResFunnelsFrontEndVo> funnelsFrontEndVo2 = data2.getFunnelsFrontEndVo();
                for (SalasOverviewResFunnelsFrontEndVo salasOverviewResFunnelsFrontEndVo : funnelsFrontEndVo2) {
                    if (ObjectUtil.equals(salasOverviewResFunnelsFrontEndVo.getModelName(),"线索")){
                        BigDecimal bigDecimal3 = new BigDecimal(salasOverviewResFunnelsFrontEndVo.getAmt());
                        try {
                            amt = amt.divide(bigDecimal3,8, RoundingMode.HALF_UP);
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    }
                    if (ObjectUtil.equals(salasOverviewResFunnelsFrontEndVo.getModelName(),"新增订单")){
                        try {
                            amt1= amt1.divide(new BigDecimal(salasOverviewResFunnelsFrontEndVo.getAmt()),8, RoundingMode.HALF_UP);
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    }
                }
            //DCC全渠道首邀率
            ModuleNameExportVO moduleNameExportVO = new ModuleNameExportVO();
            moduleNameExportVO.setAreaType("310200004");
            moduleNameExportVO.setModuleName("DCC全渠道首邀率");
            moduleNameExportVO.setAreaCode(String.valueOf(salesAreaCode));
            moduleNameExportVO.setAmt(String.valueOf(amt));
            moduleNameExportVOS.add(moduleNameExportVO);

            //DCC订单占比
            ModuleNameExportVO moduleNameExportVO1 = new ModuleNameExportVO();
            moduleNameExportVO1.setAreaType("310200004");
            moduleNameExportVO1.setModuleName("DCC订单占比");
            moduleNameExportVO1.setAreaCode(String.valueOf(salesAreaCode));
            moduleNameExportVO1.setAmt(String.valueOf(amt1));
            moduleNameExportVOS.add(moduleNameExportVO1);

            //成交率
            ModuleNameExportVO moduleNameExportVO2 = new ModuleNameExportVO();
            moduleNameExportVO2.setAreaType("310200004");
            moduleNameExportVO2.setModuleName("成交率");
            moduleNameExportVO2.setAreaCode(String.valueOf(salesAreaCode));
            moduleNameExportVO2.setAmt(String.valueOf(amt2));
            moduleNameExportVOS.add(moduleNameExportVO2);
        }
        salasOverviewReq.setNationAreaCodes(null);
        salasOverviewReq1.setNationAreaCodes(null);

        //获取销售小区目标值实际值
        List<Integer> salesDistCodes = listVO.getSalesDistCodes();
        for (Integer salesDistCode : salesDistCodes) {
            List<Integer> nationSmallDistIds=new ArrayList<>();
            nationSmallDistIds.add(salesDistCode);
            salasOverviewReq.setNationSmallDistIds(nationSmallDistIds);
            salasOverviewReq1.setNationSmallDistIds(nationSmallDistIds);
            String salasOverview1 = util.postForReportbi3(salasOverviewReq);
            SalasOverviewRes salasOverviewRes1 = JSON.parseObject(salasOverview1, SalasOverviewRes.class);
            SalasOverviewData data1 = salasOverviewRes1.getData();
            List<SalasOverviewResFunnelsFrontEndVo> funnelsFrontEndVo1 = data1.getFunnelsFrontEndVo();
            //DCC全渠道首邀率实际值
            BigDecimal amt = null;
            //DCC订单占比
            BigDecimal amt1 = null;
            //成交率
            BigDecimal amt2 = null;

                for (SalasOverviewResFunnelsFrontEndVo salasOverviewResFunnelsFrontEndVo : funnelsFrontEndVo1) {
                    if (ObjectUtil.equals(salasOverviewResFunnelsFrontEndVo.getModelName(),"新增订单")){
                        amt1  = new BigDecimal(salasOverviewResFunnelsFrontEndVo.getAmt());
                        amt2  = new BigDecimal(salasOverviewResFunnelsFrontEndVo.getAmt());
                    }
                }
                for (SalasOverviewResFunnelsFrontEndVo salasOverviewResFunnelsFrontEndVo : funnelsFrontEndVo1) {
                    if (ObjectUtil.equals(salasOverviewResFunnelsFrontEndVo.getModelName(),"首次到店")){
                        BigDecimal bigDecimal1 = new BigDecimal(salasOverviewResFunnelsFrontEndVo.getAmt());
                        BigDecimal bigDecimal2 = new BigDecimal(salasOverviewResFunnelsFrontEndVo.getAmt1());
                        amt = bigDecimal1.subtract(bigDecimal2);
                        try {
                            amt2 =amt2.divide(new BigDecimal(salasOverviewResFunnelsFrontEndVo.getAmt()),8, RoundingMode.HALF_UP);
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    }
                }
                //去除展厅到店
                String salasOverview2 = util.postForReportbi3(salasOverviewReq1);
                SalasOverviewRes salasOverviewRes2 = JSON.parseObject(salasOverview2, SalasOverviewRes.class);
                SalasOverviewData data2 = salasOverviewRes2.getData();
                List<SalasOverviewResFunnelsFrontEndVo> funnelsFrontEndVo2 = data2.getFunnelsFrontEndVo();
                for (SalasOverviewResFunnelsFrontEndVo salasOverviewResFunnelsFrontEndVo : funnelsFrontEndVo2) {
                    if (ObjectUtil.equals(salasOverviewResFunnelsFrontEndVo.getModelName(),"线索")){
                        BigDecimal bigDecimal3 = new BigDecimal(salasOverviewResFunnelsFrontEndVo.getAmt());
                        try {
                            amt = amt.divide(bigDecimal3,8, RoundingMode.HALF_UP);
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    }
                    if (ObjectUtil.equals(salasOverviewResFunnelsFrontEndVo.getModelName(),"新增订单")){
                        try {
                            amt1= amt1.divide(new BigDecimal(salasOverviewResFunnelsFrontEndVo.getAmt()),8, RoundingMode.HALF_UP);
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    }
                }
            //DCC全渠道首邀率
            ModuleNameExportVO moduleNameExportVO = new ModuleNameExportVO();
            moduleNameExportVO.setAreaType("310200002");
            moduleNameExportVO.setModuleName("DCC全渠道首邀率");
            moduleNameExportVO.setAreaCode(String.valueOf(salesDistCode));
            moduleNameExportVO.setAmt(String.valueOf(amt));
            moduleNameExportVOS.add(moduleNameExportVO);

            //DCC订单占比
            ModuleNameExportVO moduleNameExportVO1 = new ModuleNameExportVO();
            moduleNameExportVO1.setAreaType("310200002");
            moduleNameExportVO1.setModuleName("DCC订单占比");
            moduleNameExportVO1.setAreaCode(String.valueOf(salesDistCode));
            moduleNameExportVO1.setAmt(String.valueOf(amt1));
            moduleNameExportVOS.add(moduleNameExportVO1);

            //成交率
            ModuleNameExportVO moduleNameExportVO2 = new ModuleNameExportVO();
            moduleNameExportVO2.setAreaType("310200002");
            moduleNameExportVO2.setModuleName("成交率");
            moduleNameExportVO2.setAreaCode(String.valueOf(salesDistCode));
            moduleNameExportVO2.setAmt(String.valueOf(amt2));
            moduleNameExportVOS.add(moduleNameExportVO2);

        }
        salasOverviewReq.setNationSmallDistIds(null);
        salasOverviewReq1.setNationSmallDistIds(null);

        //获取全国实际值目标值
        String salasOverview1 = util.postForReportbi3(salasOverviewReq);
        SalasOverviewRes salasOverviewRes1 = JSON.parseObject(salasOverview1, SalasOverviewRes.class);
        SalasOverviewData data1 = salasOverviewRes1.getData();
        List<SalasOverviewResFunnelsFrontEndVo> funnelsFrontEndVo1 = data1.getFunnelsFrontEndVo();
        //DCC全渠道首邀率实际值
        BigDecimal amt = null;
        //DCC订单占比
        BigDecimal amt1 = null;
        //成交率
        BigDecimal amt2 = null;

            for (SalasOverviewResFunnelsFrontEndVo salasOverviewResFunnelsFrontEndVo : funnelsFrontEndVo1) {
                if (ObjectUtil.equals(salasOverviewResFunnelsFrontEndVo.getModelName(),"新增订单")){
                    amt1  = new BigDecimal(salasOverviewResFunnelsFrontEndVo.getAmt());
                    amt2  = new BigDecimal(salasOverviewResFunnelsFrontEndVo.getAmt());
                }
            }
            for (SalasOverviewResFunnelsFrontEndVo salasOverviewResFunnelsFrontEndVo : funnelsFrontEndVo1) {
                if (ObjectUtil.equals(salasOverviewResFunnelsFrontEndVo.getModelName(),"首次到店")){
                    BigDecimal bigDecimal1 = new BigDecimal(salasOverviewResFunnelsFrontEndVo.getAmt());
                    BigDecimal bigDecimal2 = new BigDecimal(salasOverviewResFunnelsFrontEndVo.getAmt1());
                    amt = bigDecimal1.subtract(bigDecimal2);
                    try {
                        amt2 =amt2.divide(new BigDecimal(salasOverviewResFunnelsFrontEndVo.getAmt()),8, RoundingMode.HALF_UP);
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            }
            //去除展厅到店
            String salasOverview2 = util.postForReportbi3(salasOverviewReq1);
            SalasOverviewRes salasOverviewRes2 = JSON.parseObject(salasOverview2, SalasOverviewRes.class);
            SalasOverviewData data2 = salasOverviewRes2.getData();
            List<SalasOverviewResFunnelsFrontEndVo> funnelsFrontEndVo2 = data2.getFunnelsFrontEndVo();
            for (SalasOverviewResFunnelsFrontEndVo salasOverviewResFunnelsFrontEndVo : funnelsFrontEndVo2) {
                if (ObjectUtil.equals(salasOverviewResFunnelsFrontEndVo.getModelName(),"线索")){
                    BigDecimal bigDecimal3 = new BigDecimal(salasOverviewResFunnelsFrontEndVo.getAmt());
                    try {
                        amt = amt.divide(bigDecimal3,8, RoundingMode.HALF_UP);
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
                if (ObjectUtil.equals(salasOverviewResFunnelsFrontEndVo.getModelName(),"新增订单")){
                    try {
                        amt1= amt1.divide(new BigDecimal(salasOverviewResFunnelsFrontEndVo.getAmt()),8, RoundingMode.HALF_UP);
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            }
        //DCC全渠道首邀率
        ModuleNameExportVO moduleNameExportVO = new ModuleNameExportVO();
        moduleNameExportVO.setAreaType("310200099");
        moduleNameExportVO.setModuleName("DCC全渠道首邀率");
        moduleNameExportVO.setAreaCode("0");
        moduleNameExportVO.setAmt(String.valueOf(amt));
        moduleNameExportVOS.add(moduleNameExportVO);

        //DCC订单占比
        ModuleNameExportVO moduleNameExportVO1 = new ModuleNameExportVO();
        moduleNameExportVO1.setAreaType("310200099");
        moduleNameExportVO1.setModuleName("DCC订单占比");
        moduleNameExportVO1.setAreaCode("0");
        moduleNameExportVO1.setAmt(String.valueOf(amt1));
        moduleNameExportVOS.add(moduleNameExportVO1);

        //成交率
        ModuleNameExportVO moduleNameExportVO2 = new ModuleNameExportVO();
        moduleNameExportVO2.setAreaType("310200099");
        moduleNameExportVO2.setModuleName("成交率");
        moduleNameExportVO2.setAreaCode("0");
        moduleNameExportVO2.setAmt(String.valueOf(amt2));
        moduleNameExportVOS.add(moduleNameExportVO2);


        return moduleNameExportVOS;
    }



    //重点开票达成-XC90/T8
    public List<ModuleNameExportVO> getModuleName4() {
        List<ModuleNameExportVO> moduleNameExportVOS=new ArrayList<>();
        SalasContrastReq salasContrastReq =new SalasContrastReq();
        salasContrastReq.setCompareType("CARCOMPARE");
        salasContrastReq.setSwitchAreaType(0);
        salasContrastReq.setTreadTypeOptions("invoicing");
        salasContrastReq.setBiType("4SA");
        salasContrastReq.setDateTypeOptions("M");
        salasContrastReq.setYear("2024");
        salasContrastReq.setMonth("3");
        salasContrastReq.setRoleCode("10461001");
        salasContrastReq.setRoleValue("10461001");

        //全国
        {
            String salasContrast = util.postForReportbi4(salasContrastReq);
            SalasContrastRes salasContrastRes = JSON.parseObject(salasContrast, SalasContrastRes.class);
            SalasContrastData data = salasContrastRes.getData();
            List<SalasContrastList> list = data.getList();
            long T8amt = 0;
            long T8targetAmt = 0;
            long XC90amt = 0;
            long XC90targetAmt = 0;
            for (SalasContrastList salasContrastList : list) {
                //T8:S60 T8,XC60 T8,XC90 T8,S90 T8
                //XC90:XC90 ICE,XC90 T8
                ActualInvcVo actualInvcVo = salasContrastList.getActualInvcVo();
                if (ObjectUtil.equals("S60 T8", actualInvcVo.getGroupByTypeName())) {
                    T8amt = T8amt + actualInvcVo.getAmt();
                    T8targetAmt = T8targetAmt + actualInvcVo.getTargetAmt();
                }
                if (ObjectUtil.equals("XC60 T8", actualInvcVo.getGroupByTypeName())) {
                    T8amt = T8amt + actualInvcVo.getAmt();
                    T8targetAmt = T8targetAmt + actualInvcVo.getTargetAmt();
                }
                if (ObjectUtil.equals("XC90 T8", actualInvcVo.getGroupByTypeName())) {
                    T8amt = T8amt + actualInvcVo.getAmt();
                    T8targetAmt = T8targetAmt + actualInvcVo.getTargetAmt();
                    XC90amt = XC90amt + actualInvcVo.getAmt();
                    XC90targetAmt = XC90targetAmt + actualInvcVo.getTargetAmt();
                }
                if (ObjectUtil.equals("XC90 ICE", actualInvcVo.getGroupByTypeName())) {
                    XC90amt = XC90amt + actualInvcVo.getAmt();
                    XC90targetAmt = XC90targetAmt + actualInvcVo.getTargetAmt();
                }
                if (ObjectUtil.equals("S90 T8", actualInvcVo.getGroupByTypeName())) {
                    T8amt = T8amt + actualInvcVo.getAmt();
                    T8targetAmt = T8targetAmt + actualInvcVo.getTargetAmt();
                }
            }
            ModuleNameExportVO moduleNameExportVO = new ModuleNameExportVO();
            moduleNameExportVO.setAreaType("310200099");
            moduleNameExportVO.setModuleName("重点开票达成-T8");
            moduleNameExportVO.setAreaCode("0");
            moduleNameExportVO.setAmt(String.valueOf(T8amt));
            moduleNameExportVO.setTargetAmt(String.valueOf(T8targetAmt));
            moduleNameExportVOS.add(moduleNameExportVO);
            ModuleNameExportVO moduleNameExportVO1 = new ModuleNameExportVO();
            moduleNameExportVO1.setAreaType("310200099");
            moduleNameExportVO1.setModuleName("重点开票达成-XC90");
            moduleNameExportVO1.setAreaCode("0");
            moduleNameExportVO1.setAmt(String.valueOf(XC90amt));
            moduleNameExportVO1.setTargetAmt(String.valueOf(XC90targetAmt));
            moduleNameExportVOS.add(moduleNameExportVO1);
        }

        //获取经销商信息
        ListVO listVO = getEtlDimSalesDealerInfoHis();
        List<String> dealerCodes = listVO.getDealerCodes();
        //获取经销商目标值实际值
        for (String dealerCode : dealerCodes) {
            List<String> nationDealerCodes = new ArrayList<>();
            nationDealerCodes.add(dealerCode);
            salasContrastReq.setNationDealerCodes(nationDealerCodes);
            String salasContrast = util.postForReportbi4(salasContrastReq);
            SalasContrastRes salasContrastRes = JSON.parseObject(salasContrast, SalasContrastRes.class);
            SalasContrastData data = salasContrastRes.getData();
            List<SalasContrastList> list = data.getList();
            long T8amt = 0;
            long T8targetAmt = 0;
            long XC90amt = 0;
            long XC90targetAmt = 0;
            for (SalasContrastList salasContrastList : list) {
                //T8:S60 T8,XC60 T8,XC90 T8,S90 T8
                //XC90:XC90 ICE,XC90 T8
                ActualInvcVo actualInvcVo = salasContrastList.getActualInvcVo();
                if (ObjectUtil.equals("S60 T8", actualInvcVo.getGroupByTypeName())) {
                    T8amt = T8amt + actualInvcVo.getAmt();
                    T8targetAmt = T8targetAmt + actualInvcVo.getTargetAmt();
                }
                if (ObjectUtil.equals("XC60 T8", actualInvcVo.getGroupByTypeName())) {
                    T8amt = T8amt + actualInvcVo.getAmt();
                    T8targetAmt = T8targetAmt + actualInvcVo.getTargetAmt();
                }
                if (ObjectUtil.equals("XC90 T8", actualInvcVo.getGroupByTypeName())) {
                    T8amt = T8amt + actualInvcVo.getAmt();
                    T8targetAmt = T8targetAmt + actualInvcVo.getTargetAmt();
                    XC90amt = XC90amt + actualInvcVo.getAmt();
                    XC90targetAmt = XC90targetAmt + actualInvcVo.getTargetAmt();
                }
                if (ObjectUtil.equals("XC90 ICE", actualInvcVo.getGroupByTypeName())) {
                    XC90amt = XC90amt + actualInvcVo.getAmt();
                    XC90targetAmt = XC90targetAmt + actualInvcVo.getTargetAmt();
                }
                if (ObjectUtil.equals("S90 T8", actualInvcVo.getGroupByTypeName())) {
                    T8amt = T8amt + actualInvcVo.getAmt();
                    T8targetAmt = T8targetAmt + actualInvcVo.getTargetAmt();
                }
            }
            ModuleNameExportVO moduleNameExportVO = new ModuleNameExportVO();
            moduleNameExportVO.setAreaType("310200001");
            moduleNameExportVO.setModuleName("重点开票达成-T8");
            moduleNameExportVO.setAreaCode(dealerCode);
            moduleNameExportVO.setAmt(String.valueOf(T8amt));
            moduleNameExportVO.setTargetAmt(String.valueOf(T8targetAmt));
            moduleNameExportVOS.add(moduleNameExportVO);
            ModuleNameExportVO moduleNameExportVO1 = new ModuleNameExportVO();
            moduleNameExportVO1.setAreaType("310200001");
            moduleNameExportVO1.setModuleName("重点开票达成-XC90");
            moduleNameExportVO1.setAreaCode(dealerCode);
            moduleNameExportVO1.setAmt(String.valueOf(XC90amt));
            moduleNameExportVO1.setTargetAmt(String.valueOf(XC90targetAmt));
            moduleNameExportVOS.add(moduleNameExportVO1);
        }
        salasContrastReq.setNationDealerCodes(null);

        //获取销售大区目标值实际值
        List<Integer> salesAreaCodes = listVO.getSalesAreaCodes();
        for (Integer salesAreaCode : salesAreaCodes) {

            List<Integer> nationAreaCodes = new ArrayList<>();
            nationAreaCodes.add(salesAreaCode);
            salasContrastReq.setNationAreaCodes(nationAreaCodes);
            String salasContrast = util.postForReportbi4(salasContrastReq);
            SalasContrastRes salasContrastRes = JSON.parseObject(salasContrast, SalasContrastRes.class);
            SalasContrastData data = salasContrastRes.getData();
            List<SalasContrastList> list = data.getList();
            long T8amt = 0;
            long T8targetAmt = 0;
            long XC90amt = 0;
            long XC90targetAmt = 0;
            for (SalasContrastList salasContrastList : list) {
                //T8:S60 T8,XC60 T8,XC90 T8,S90 T8
                //XC90:XC90 ICE,XC90 T8
                ActualInvcVo actualInvcVo = salasContrastList.getActualInvcVo();
                if (ObjectUtil.equals("S60 T8", actualInvcVo.getGroupByTypeName())) {
                    T8amt = T8amt + actualInvcVo.getAmt();
                    T8targetAmt = T8targetAmt + actualInvcVo.getTargetAmt();
                }
                if (ObjectUtil.equals("XC60 T8", actualInvcVo.getGroupByTypeName())) {
                    T8amt = T8amt + actualInvcVo.getAmt();
                    T8targetAmt = T8targetAmt + actualInvcVo.getTargetAmt();
                }
                if (ObjectUtil.equals("XC90 T8", actualInvcVo.getGroupByTypeName())) {
                    T8amt = T8amt + actualInvcVo.getAmt();
                    T8targetAmt = T8targetAmt + actualInvcVo.getTargetAmt();
                    XC90amt = XC90amt + actualInvcVo.getAmt();
                    XC90targetAmt = XC90targetAmt + actualInvcVo.getTargetAmt();
                }
                if (ObjectUtil.equals("XC90 ICE", actualInvcVo.getGroupByTypeName())) {
                    XC90amt = XC90amt + actualInvcVo.getAmt();
                    XC90targetAmt = XC90targetAmt + actualInvcVo.getTargetAmt();
                }
                if (ObjectUtil.equals("S90 T8", actualInvcVo.getGroupByTypeName())) {
                    T8amt = T8amt + actualInvcVo.getAmt();
                    T8targetAmt = T8targetAmt + actualInvcVo.getTargetAmt();
                }
            }
            ModuleNameExportVO moduleNameExportVO = new ModuleNameExportVO();
            moduleNameExportVO.setAreaType("310200004");
            moduleNameExportVO.setModuleName("重点开票达成-T8");
            moduleNameExportVO.setAreaCode(String.valueOf(salesAreaCode));
            moduleNameExportVO.setAmt(String.valueOf(T8amt));
            moduleNameExportVO.setTargetAmt(String.valueOf(T8targetAmt));
            moduleNameExportVOS.add(moduleNameExportVO);
            ModuleNameExportVO moduleNameExportVO1 = new ModuleNameExportVO();
            moduleNameExportVO1.setAreaType("310200004");
            moduleNameExportVO1.setModuleName("重点开票达成-XC90");
            moduleNameExportVO1.setAreaCode(String.valueOf(salesAreaCode));
            moduleNameExportVO1.setAmt(String.valueOf(XC90amt));
            moduleNameExportVO1.setTargetAmt(String.valueOf(XC90targetAmt));
            moduleNameExportVOS.add(moduleNameExportVO1);
        }
        salasContrastReq.setNationAreaCodes(null);

        List<Integer> salesDistCodes = listVO.getSalesDistCodes();
        for (Integer salesDistCode : salesDistCodes) {
            List<Integer> nationSmallDistIds=new ArrayList<>();
            nationSmallDistIds.add(salesDistCode);
            salasContrastReq.setNationSmallDistIds(nationSmallDistIds);
            String salasContrast = util.postForReportbi4(salasContrastReq);
            SalasContrastRes salasContrastRes = JSON.parseObject(salasContrast, SalasContrastRes.class);
            SalasContrastData data = salasContrastRes.getData();
            List<SalasContrastList> list = data.getList();
            long T8amt = 0;
            long T8targetAmt = 0;
            long XC90amt = 0;
            long XC90targetAmt = 0;
            for (SalasContrastList salasContrastList : list) {
                //T8:S60 T8,XC60 T8,XC90 T8,S90 T8
                //XC90:XC90 ICE,XC90 T8
                ActualInvcVo actualInvcVo = salasContrastList.getActualInvcVo();
                if (ObjectUtil.equals("S60 T8", actualInvcVo.getGroupByTypeName())) {
                    T8amt = T8amt + actualInvcVo.getAmt();
                    T8targetAmt = T8targetAmt + actualInvcVo.getTargetAmt();
                }
                if (ObjectUtil.equals("XC60 T8", actualInvcVo.getGroupByTypeName())) {
                    T8amt = T8amt + actualInvcVo.getAmt();
                    T8targetAmt = T8targetAmt + actualInvcVo.getTargetAmt();
                }
                if (ObjectUtil.equals("XC90 T8", actualInvcVo.getGroupByTypeName())) {
                    T8amt = T8amt + actualInvcVo.getAmt();
                    T8targetAmt = T8targetAmt + actualInvcVo.getTargetAmt();
                    XC90amt = XC90amt + actualInvcVo.getAmt();
                    XC90targetAmt = XC90targetAmt + actualInvcVo.getTargetAmt();
                }
                if (ObjectUtil.equals("XC90 ICE", actualInvcVo.getGroupByTypeName())) {
                    XC90amt = XC90amt + actualInvcVo.getAmt();
                    XC90targetAmt = XC90targetAmt + actualInvcVo.getTargetAmt();
                }
                if (ObjectUtil.equals("S90 T8", actualInvcVo.getGroupByTypeName())) {
                    T8amt = T8amt + actualInvcVo.getAmt();
                    T8targetAmt = T8targetAmt + actualInvcVo.getTargetAmt();
                }
            }
            ModuleNameExportVO moduleNameExportVO = new ModuleNameExportVO();
            moduleNameExportVO.setAreaType("310200002");
            moduleNameExportVO.setModuleName("重点开票达成-T8");
            moduleNameExportVO.setAreaCode(String.valueOf(salesDistCode));
            moduleNameExportVO.setAmt(String.valueOf(T8amt));
            moduleNameExportVO.setTargetAmt(String.valueOf(T8targetAmt));
            moduleNameExportVOS.add(moduleNameExportVO);
            ModuleNameExportVO moduleNameExportVO1 = new ModuleNameExportVO();
            moduleNameExportVO1.setAreaType("310200002");
            moduleNameExportVO1.setModuleName("重点开票达成-XC90");
            moduleNameExportVO1.setAreaCode(String.valueOf(salesDistCode));
            moduleNameExportVO1.setAmt(String.valueOf(XC90amt));
            moduleNameExportVO1.setTargetAmt(String.valueOf(XC90targetAmt));
            moduleNameExportVOS.add(moduleNameExportVO1);
        }
        return moduleNameExportVOS;
    }


//二邀率
    public List<ModuleNameExportVO> getModuleName5() {
        List<ModuleNameExportVO> moduleNameExportVOS = new ArrayList<>();
        TaendContrastReq taendContrastReq = new TaendContrastReq();
        taendContrastReq.setCompareType("TREND");
        taendContrastReq.setBiType("4SA");
        taendContrastReq.setDateTypeOptions("M");
        taendContrastReq.setYear("2024");
        taendContrastReq.setMonth("3");
        taendContrastReq.setTreadTypeOptions("secondInviteArrival");
        taendContrastReq.setRoleCode("10461001");
        taendContrastReq.setRoleValue("10461001");

        //全国
        {
            String taendContrast = util.postForReportbi5(taendContrastReq);
            TaendContrastRes taendContrastRes = JSON.parseObject(taendContrast, TaendContrastRes.class);
            TaendContrastData data = taendContrastRes.getData();
            List<FirstArrival> firstArrival = data.getFirstArrival();
            List<SecondInviteArrival> secondInviteArrival = data.getSecondInviteArrival();
            //首次
            BigDecimal amt = null;
            //二次
            BigDecimal amt1 = null;
            //二邀率
            BigDecimal divide = null;
            for (FirstArrival arrival : firstArrival) {
                if (ObjectUtil.equals(arrival.getMonth(), 3l)) {
                    amt = new BigDecimal(arrival.getAmt());
                }
            }
            for (SecondInviteArrival inviteArrival : secondInviteArrival) {
                if (ObjectUtil.equals(inviteArrival.getMonth(), 3l)) {
                    amt1 = new BigDecimal(inviteArrival.getAmt());
                }
            }
            try {
                divide = amt1.divide(amt, 8, RoundingMode.HALF_UP);
            } catch (Exception e) {
                e.printStackTrace();
            }
            ModuleNameExportVO moduleNameExportVO = new ModuleNameExportVO();
            moduleNameExportVO.setAreaType("310200099");
            moduleNameExportVO.setModuleName("二邀率");
            moduleNameExportVO.setAreaCode("0");
            moduleNameExportVO.setAmt(String.valueOf(divide));
            moduleNameExportVOS.add(moduleNameExportVO);
        }

        //获取经销商信息
        ListVO listVO = getEtlDimSalesDealerInfoHis();
        List<String> dealerCodes = listVO.getDealerCodes();
        //获取经销商目标值实际值
        for (String dealerCode : dealerCodes) {
            List<String> nationDealerCodes = new ArrayList<>();
            nationDealerCodes.add(dealerCode);
            taendContrastReq.setNationDealerCodes(nationDealerCodes);
            String taendContrast = util.postForReportbi5(taendContrastReq);
            TaendContrastRes taendContrastRes = JSON.parseObject(taendContrast, TaendContrastRes.class);
            TaendContrastData data = taendContrastRes.getData();
            List<FirstArrival> firstArrival = data.getFirstArrival();
            List<SecondInviteArrival> secondInviteArrival = data.getSecondInviteArrival();
            //首次
            BigDecimal amt = null;
            //二次
            BigDecimal amt1 = null;
            //二邀率
            BigDecimal divide = null;
            for (FirstArrival arrival : firstArrival) {
                if (ObjectUtil.equals(arrival.getMonth(), 3l)) {
                    amt = new BigDecimal(arrival.getAmt());
                }
            }
            for (SecondInviteArrival inviteArrival : secondInviteArrival) {
                if (ObjectUtil.equals(inviteArrival.getMonth(), 3l)) {
                    amt1 = new BigDecimal(inviteArrival.getAmt());
                }
            }
            try {
                divide = amt1.divide(amt, 8, RoundingMode.HALF_UP);
            } catch (Exception e) {
                e.printStackTrace();
            }
            ModuleNameExportVO moduleNameExportVO = new ModuleNameExportVO();
            moduleNameExportVO.setAreaType("310200001");
            moduleNameExportVO.setModuleName("二邀率");
            moduleNameExportVO.setAreaCode(dealerCode);
            moduleNameExportVO.setAmt(String.valueOf(divide));
            moduleNameExportVOS.add(moduleNameExportVO);

        }
        taendContrastReq.setNationDealerCodes(null);

        //获取销售大区目标值实际值
        List<Integer> salesAreaCodes = listVO.getSalesAreaCodes();
        for (Integer salesAreaCode : salesAreaCodes) {

            List<Integer> nationAreaCodes = new ArrayList<>();
            nationAreaCodes.add(salesAreaCode);
            taendContrastReq.setNationAreaCodes(nationAreaCodes);
            String taendContrast = util.postForReportbi5(taendContrastReq);
            TaendContrastRes taendContrastRes = JSON.parseObject(taendContrast, TaendContrastRes.class);
            TaendContrastData data = taendContrastRes.getData();
            List<FirstArrival> firstArrival = data.getFirstArrival();
            List<SecondInviteArrival> secondInviteArrival = data.getSecondInviteArrival();
            //首次
            BigDecimal amt = null;
            //二次
            BigDecimal amt1 = null;
            //二邀率
            BigDecimal divide = null;
            for (FirstArrival arrival : firstArrival) {
                if (ObjectUtil.equals(arrival.getMonth(), 3l)) {
                    amt = new BigDecimal(arrival.getAmt());
                }
            }
            for (SecondInviteArrival inviteArrival : secondInviteArrival) {
                if (ObjectUtil.equals(inviteArrival.getMonth(), 3l)) {
                    amt1 = new BigDecimal(inviteArrival.getAmt());
                }
            }
            try {
                divide = amt1.divide(amt, 8, RoundingMode.HALF_UP);
            } catch (Exception e) {
                e.printStackTrace();
            }
            ModuleNameExportVO moduleNameExportVO = new ModuleNameExportVO();
            moduleNameExportVO.setAreaType("310200004");
            moduleNameExportVO.setModuleName("二邀率");
            moduleNameExportVO.setAreaCode(String.valueOf(salesAreaCode));
            moduleNameExportVO.setAmt(String.valueOf(divide));
            moduleNameExportVOS.add(moduleNameExportVO);
        }
        //获取销售小区目标值实际值
        taendContrastReq.setNationAreaCodes(null);

        List<Integer> salesDistCodes = listVO.getSalesDistCodes();
        for (Integer salesDistCode : salesDistCodes) {
            List<Integer> nationSmallDistIds=new ArrayList<>();
            nationSmallDistIds.add(salesDistCode);
            taendContrastReq.setNationSmallDistIds(nationSmallDistIds);
            String taendContrast = util.postForReportbi5(taendContrastReq);
            TaendContrastRes taendContrastRes = JSON.parseObject(taendContrast, TaendContrastRes.class);
            TaendContrastData data = taendContrastRes.getData();
            List<FirstArrival> firstArrival = data.getFirstArrival();
            List<SecondInviteArrival> secondInviteArrival = data.getSecondInviteArrival();
            //首次
            BigDecimal amt = null;
            //二次
            BigDecimal amt1 = null;
            //二邀率
            BigDecimal divide = null;
            for (FirstArrival arrival : firstArrival) {
                if (ObjectUtil.equals(arrival.getMonth(), 3l)) {
                    amt = new BigDecimal(arrival.getAmt());
                }
            }
            for (SecondInviteArrival inviteArrival : secondInviteArrival) {
                if (ObjectUtil.equals(inviteArrival.getMonth(), 3l)) {
                    amt1 = new BigDecimal(inviteArrival.getAmt());
                }
            }
            try {
                divide = amt1.divide(amt, 8, RoundingMode.HALF_UP);
            } catch (Exception e) {
                e.printStackTrace();
            }
            ModuleNameExportVO moduleNameExportVO = new ModuleNameExportVO();
            moduleNameExportVO.setAreaType("310200002");
            moduleNameExportVO.setModuleName("二邀率");
            moduleNameExportVO.setAreaCode(String.valueOf(salesDistCode));
            moduleNameExportVO.setAmt(String.valueOf(divide));
            moduleNameExportVOS.add(moduleNameExportVO);
        }
        return moduleNameExportVOS;

    }

    @Override
    public void exportModuleName(HttpServletResponse response) {
        List<ModuleNameExportVO> moduleNameExportVOS=new ArrayList<>();
        List<ModuleNameExportVO> moduleName1 = getModuleName1();
        List<ModuleNameExportVO> moduleName2 = getModuleName2();
        List<ModuleNameExportVO> moduleName3 = getModuleName3();
        List<ModuleNameExportVO> moduleName4 = getModuleName4();
        List<ModuleNameExportVO> moduleName5 = getModuleName5();
        moduleNameExportVOS.addAll(moduleName1);
        moduleNameExportVOS.addAll(moduleName2);
        moduleNameExportVOS.addAll(moduleName3);
        moduleNameExportVOS.addAll(moduleName4);
        moduleNameExportVOS.addAll(moduleName5);

        try {
            response.setContentType("application/vnd.excel");
            response.setCharacterEncoding("utf-8");
            String fileName= URLEncoder.encode("销售BI","UTF-8").replaceAll("\\+","%20");
            response.setHeader("Content-disposition","attachment;filename="+fileName+".xlsx");
            //写入数据
            EasyExcel.write(response.getOutputStream(), ModuleNameExportVO.class).sheet("sheet1").doWrite(moduleNameExportVOS);
        } catch (IOException e) {
            e.printStackTrace();
        }

    }

    @Override
    public void exportModuleNameNbm(HttpServletResponse response) {
        List<ModuleNameExportVO> moduleNameExportVOS=new ArrayList<>();
        List<ModuleNameExportVO> moduleName6 = getModuleName6();
        List<ModuleNameExportVO> moduleName7 = getModuleName7();

        moduleNameExportVOS.addAll(moduleName6);
        moduleNameExportVOS.addAll(moduleName7);


        try {
            response.setContentType("application/vnd.excel");
            response.setCharacterEncoding("utf-8");
            String fileName= URLEncoder.encode("nbm","UTF-8").replaceAll("\\+","%20");
            response.setHeader("Content-disposition","attachment;filename="+fileName+".xlsx");
            //写入数据
            EasyExcel.write(response.getOutputStream(), ModuleNameExportVO.class).sheet("sheet1").doWrite(moduleNameExportVOS);
        } catch (IOException e) {
            e.printStackTrace();
        }

    }


    //EBT（税前净利润),税前净利润率（ROS）,零服吸收率
    public List<ModuleNameExportVO> getModuleName6() {
        List<ModuleNameExportVO> moduleNameExportVOS = new ArrayList<>();
        //mtd
        {
            DisplayBoardReq displayBoardReq = new DisplayBoardReq();
            displayBoardReq.setDataMonth("202403");
            displayBoardReq.setProfitType("MTD");
            //全国
            extracted(moduleNameExportVOS, displayBoardReq, "310200099", "MTD", "0");
            //获取经销商信息
            ListVO listVO = getEtlDimSalesDealerInfoHis();
            List<String> dealerCodes = listVO.getDealerCodes();
            //获取经销商目标值实际值
            for (String dealerCode : dealerCodes) {
                List<String> nationDealerCodes = new ArrayList<>();
                nationDealerCodes.add(dealerCode);
                displayBoardReq.setGroupDlrCodeList(nationDealerCodes);
                extracted(moduleNameExportVOS, displayBoardReq, "310200001", "MTD", dealerCode);
                displayBoardReq.setRegionDlrCodeList(null);
            }

            List<String> salesAreaNames = listVO.getSalesAreaNames();
            //获取大区目标值实际值
            for (String salesAreaName : salesAreaNames) {
                List<String> largeRegionNameList = new ArrayList<>();
                largeRegionNameList.add(salesAreaName);
                displayBoardReq.setLargeRegionNameList(largeRegionNameList);
                extracted(moduleNameExportVOS, displayBoardReq, "310200004", "MTD", salesAreaName);
                displayBoardReq.setLargeRegionNameList(null);
            }

            List<String> salesDistNames = listVO.getSalesDistNames();
            //获取小区目标值实际值
            for (String salesDistName : salesDistNames) {
                List<String> villageRegionNameList = new ArrayList<>();
                villageRegionNameList.add(salesDistName);
                displayBoardReq.setVillageRegionNameList(villageRegionNameList);
                extracted(moduleNameExportVOS, displayBoardReq, "310200004", "MTD", salesDistName);
                displayBoardReq.setLargeRegionNameList(null);
            }
        }

        //YTD
        DisplayBoardReq displayBoardReq = new DisplayBoardReq();
        displayBoardReq.setDataMonth("202403");
        displayBoardReq.setProfitType("YTD");

        extractedYTD(moduleNameExportVOS, displayBoardReq, "310200099", "YTD", "0");
        //获取经销商信息
        ListVO listVO = getEtlDimSalesDealerInfoHis();
        List<String> dealerCodes = listVO.getDealerCodes();
        //获取经销商目标值实际值
        for (String dealerCode : dealerCodes) {
            List<String> nationDealerCodes = new ArrayList<>();
            nationDealerCodes.add(dealerCode);
            displayBoardReq.setGroupDlrCodeList(nationDealerCodes);
            extractedYTD(moduleNameExportVOS, displayBoardReq, "310200001","YTD", dealerCode);
            displayBoardReq.setRegionDlrCodeList(null);
        }

        List<String> salesAreaNames = listVO.getSalesAreaNames();
        //获取大区目标值实际值
        for (String salesAreaName : salesAreaNames) {
            List<String> largeRegionNameList = new ArrayList<>();
            largeRegionNameList.add(salesAreaName);
            displayBoardReq.setLargeRegionNameList(largeRegionNameList);
            extractedYTD(moduleNameExportVOS, displayBoardReq, "310200004","YTD", salesAreaName);
            displayBoardReq.setLargeRegionNameList(null);
        }

        List<String> salesDistNames = listVO.getSalesDistNames();
        //获取小区目标值实际值
        for (String salesDistName : salesDistNames) {
            List<String> villageRegionNameList = new ArrayList<>();
            villageRegionNameList.add(salesDistName);
            displayBoardReq.setVillageRegionNameList(villageRegionNameList);
            extractedYTD(moduleNameExportVOS, displayBoardReq, "310200004","YTD", salesDistName);
            displayBoardReq.setLargeRegionNameList(null);
        }

        return moduleNameExportVOS;
    }

    private void extracted(List<ModuleNameExportVO> moduleNameExportVOS, DisplayBoardReq displayBoardReq, String areaType, String mouthType, String dealerCode) {
        String displayBoard = util.postForReportbi6(displayBoardReq);
        DisplayBoardRes displayBoardRes = JSON.parseObject(displayBoard, DisplayBoardRes.class);
        DisplayBoardRes.DataDTO data = displayBoardRes.getData();
        DisplayBoardRes.DataDTO.ProfitDTO profit = data.getProfit();
        //EBT（税前净利润
        String earnings = profit.getEarnings();
        ModuleNameExportVO moduleNameExportVO = new ModuleNameExportVO();
        moduleNameExportVO.setModuleName("EBT（税前净利润)");
        moduleNameExportVO.setAmt(earnings);
        moduleNameExportVO.setAreaType(areaType);
        moduleNameExportVO.setAreaCode(dealerCode);
        moduleNameExportVO.setMouthType(mouthType);
        moduleNameExportVOS.add(moduleNameExportVO);
        //税前净利润率（ROS）
        String ros = profit.getRos();
        ModuleNameExportVO moduleNameExportVO1 = new ModuleNameExportVO();
        moduleNameExportVO1.setModuleName("税前净利润率（ROS）");
        moduleNameExportVO1.setAmt(ros);
        moduleNameExportVO1.setAreaType(areaType);
        moduleNameExportVO1.setAreaCode(dealerCode);
        moduleNameExportVO1.setMouthType(mouthType);
        moduleNameExportVOS.add(moduleNameExportVO1);
    }

    private void extractedYTD(List<ModuleNameExportVO> moduleNameExportVOS, DisplayBoardReq displayBoardReq, String areaType, String mouthType, String dealerCode) {
        String displayBoard = util.postForReportbi6(displayBoardReq);
        DisplayBoardRes displayBoardRes = JSON.parseObject(displayBoard, DisplayBoardRes.class);
        DisplayBoardRes.DataDTO data = displayBoardRes.getData();
        DisplayBoardRes.DataDTO.ProfitDTO profit = data.getProfit();
        DisplayBoardRes.DataDTO.AfterSalesDTO afterSales = data.getAfterSales();
        //EBT（税前净利润
        String earnings = profit.getEarnings();
        ModuleNameExportVO moduleNameExportVO = new ModuleNameExportVO();
        moduleNameExportVO.setModuleName("EBT（税前净利润)");
        moduleNameExportVO.setAmt(earnings);
        moduleNameExportVO.setAreaType(areaType);
        moduleNameExportVO.setAreaCode(dealerCode);
        moduleNameExportVO.setMouthType(mouthType);
        moduleNameExportVOS.add(moduleNameExportVO);
        //税前净利润率（ROS）
        String ros = profit.getRos();
        ModuleNameExportVO moduleNameExportVO1 = new ModuleNameExportVO();
        moduleNameExportVO1.setModuleName("税前净利润率（ROS）");
        moduleNameExportVO1.setAmt(ros);
        moduleNameExportVO1.setAreaType(areaType);
        moduleNameExportVO1.setAreaCode(dealerCode);
        moduleNameExportVO1.setMouthType(mouthType);
        moduleNameExportVOS.add(moduleNameExportVO1);
        //零服吸收率
        String afterSalesPerCent = afterSales.getAfterSalesPerCent();
        ModuleNameExportVO moduleNameExportVO2 = new ModuleNameExportVO();
        moduleNameExportVO2.setModuleName("零服吸收率");
        moduleNameExportVO2.setAmt(afterSalesPerCent);
        moduleNameExportVO2.setAreaType(areaType);
        moduleNameExportVO2.setAreaCode(dealerCode);
        moduleNameExportVO2.setMouthType(mouthType);
        moduleNameExportVOS.add(moduleNameExportVO2);
    }


    //新车GP1%,新车GP2%
    public List<ModuleNameExportVO> getModuleName7() {
        List<ModuleNameExportVO> moduleNameExportVOS = new ArrayList<>();
        //mtd
        {
            NewCarBusinessReq newCarBusinessReq = new NewCarBusinessReq();
            newCarBusinessReq.setDataMonth(202403);
            newCarBusinessReq.setProfitType("MTD");
            //全国
            extractedGP(moduleNameExportVOS, newCarBusinessReq, "310200099","0",  "MTD");
            //获取经销商信息
            ListVO listVO = getEtlDimSalesDealerInfoHis();
            List<String> dealerCodes = listVO.getDealerCodes();
            //获取经销商目标值实际值
            for (String dealerCode : dealerCodes) {
                List<String> nationDealerCodes = new ArrayList<>();
                nationDealerCodes.add(dealerCode);
                newCarBusinessReq.setGroupDlrCodeList(nationDealerCodes);
                extractedGP(moduleNameExportVOS, newCarBusinessReq, "310200001", dealerCode, "MTD");
                newCarBusinessReq.setRegionDlrCodeList(null);
            }

            List<String> salesAreaNames = listVO.getSalesAreaNames();
            //获取大区目标值实际值
            for (String salesAreaName : salesAreaNames) {
                List<String> largeRegionNameList = new ArrayList<>();
                largeRegionNameList.add(salesAreaName);
                newCarBusinessReq.setLargeRegionNameList(largeRegionNameList);
                extractedGP(moduleNameExportVOS, newCarBusinessReq, "310200004", salesAreaName, "MTD");
                newCarBusinessReq.setLargeRegionNameList(null);
            }

            List<String> salesDistNames = listVO.getSalesDistNames();
            //获取小区目标值实际值
            for (String salesDistName : salesDistNames) {
                List<String> villageRegionNameList = new ArrayList<>();
                villageRegionNameList.add(salesDistName);
                newCarBusinessReq.setVillageRegionNameList(villageRegionNameList);
                extractedGP(moduleNameExportVOS, newCarBusinessReq, "310200002", salesDistName, "MTD");
                newCarBusinessReq.setLargeRegionNameList(null);
            }
        }
        //YTD
        NewCarBusinessReq newCarBusinessReq = new NewCarBusinessReq();
        newCarBusinessReq.setDataMonth(202403);
        newCarBusinessReq.setProfitType("YTD");
        //全国
        extractedGP(moduleNameExportVOS, newCarBusinessReq, "310200099", "0", "YTD");
        //获取经销商信息
        ListVO listVO = getEtlDimSalesDealerInfoHis();
        List<String> dealerCodes = listVO.getDealerCodes();
        //获取经销商目标值实际值
        for (String dealerCode : dealerCodes) {
            List<String> nationDealerCodes = new ArrayList<>();
            nationDealerCodes.add(dealerCode);
            newCarBusinessReq.setGroupDlrCodeList(nationDealerCodes);
            extractedGP(moduleNameExportVOS, newCarBusinessReq, "310200001", dealerCode, "YTD");
            newCarBusinessReq.setRegionDlrCodeList(null);
        }

        List<String> salesAreaNames = listVO.getSalesAreaNames();
        //获取大区目标值实际值
        for (String salesAreaName : salesAreaNames) {
            List<String> largeRegionNameList = new ArrayList<>();
            largeRegionNameList.add(salesAreaName);
            newCarBusinessReq.setLargeRegionNameList(largeRegionNameList);
            extractedGP(moduleNameExportVOS, newCarBusinessReq, "310200004", salesAreaName, "YTD");
            newCarBusinessReq.setLargeRegionNameList(null);
        }

        List<String> salesDistNames = listVO.getSalesDistNames();
        //获取小区目标值实际值
        for (String salesDistName : salesDistNames) {
            List<String> villageRegionNameList = new ArrayList<>();
            villageRegionNameList.add(salesDistName);
            newCarBusinessReq.setVillageRegionNameList(villageRegionNameList);
            extractedGP(moduleNameExportVOS, newCarBusinessReq, "YTD", salesDistName, "310200002");
            newCarBusinessReq.setLargeRegionNameList(null);
        }
        return moduleNameExportVOS;
    }

    private void extractedGP(List<ModuleNameExportVO> moduleNameExportVOS, NewCarBusinessReq newCarBusinessReq, String areaType, String dealerCode, String mouthType) {
        String newCarBusiness = util.postForReportbi7(newCarBusinessReq);
        NewCarBusinessRes newCarBusinessRes = JSON.parseObject(newCarBusiness, NewCarBusinessRes.class);
        NewCarBusinessRes.DataDTO data = newCarBusinessRes.getData();
        List<NewCarBusinessRes.DataDTO.GpDTO> gp = data.getGp();
        String gp1=null;
        String gp2=null;
        for (NewCarBusinessRes.DataDTO.GpDTO gpDTO : gp) {
            if (ObjectUtil.equals("GP1",gpDTO.getName())){
                gp1=gpDTO.getGpRatio();
            }
            if (ObjectUtil.equals("GP2",gpDTO.getName())){
                gp2=gpDTO.getGpRatio();
            }
        }
        //gp1
        ModuleNameExportVO moduleNameExportVO = new ModuleNameExportVO();
        moduleNameExportVO.setModuleName("新车GP1%");
        moduleNameExportVO.setAmt(gp1);
        moduleNameExportVO.setAreaType(areaType);
        moduleNameExportVO.setAreaCode(dealerCode);
        moduleNameExportVO.setMouthType(mouthType);
        moduleNameExportVOS.add(moduleNameExportVO);
        //gp2
        ModuleNameExportVO moduleNameExportVO1 = new ModuleNameExportVO();
        moduleNameExportVO1.setModuleName("新车GP2%");
        moduleNameExportVO1.setAmt(gp2);
        moduleNameExportVO1.setAreaType(areaType);
        moduleNameExportVO1.setAreaCode(dealerCode);
        moduleNameExportVO1.setMouthType(mouthType);
        moduleNameExportVOS.add(moduleNameExportVO1);
    }


}
